home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-08-19 | 2.0 KB | 86 lines | [TEXT/R*ch] |
- Various bits of source from the Getting Started September article
-
-
-
- The CPushButton class definition might look something like this:
-
- class CPushButton
- {
- protected:
- Rect bounds;
- Str255 title;
- Boolean isDefault;
- WindowPtr owningWindow;
- ControlHandle buttonControl;
-
- public:
- CPushButton( WindowPtr owningWindow, Rect *bounds,
- Str255 title, Boolean isDefault );
- virtual ~CPushButton();
- virtual void Draw();
- virtual void DoClick();
- };
- Here’s my definition of a CPictureButton class:
-
- class CPictureButton : public CPushButton
- {
- protected:
- PicHandle pic;
-
- public:
- CPictureButton( WindowPtr owningWindow, Rect *bounds,
- PicHandle pic, Boolean isDefault );
- virtual ~CPushButton();
- virtual void Draw();
- virtual void DoClick();
- };
-
-
- Here’s a CPictureButton definition:
-
- CPictureButton *myPictureButton;
-
- myPictureButton = new CPictureButton( myWindow,
- &buttonRect, myPicture, true );
-
- When you create a derived class object, you provide the parameters you want
- passed to the derived classes’ constructor:
-
- CPictureButton *myPictureButton;
-
- myPictureButton = new CPictureButton( myWindow,
- &buttonRect, myPicture, true );
-
- The format of the base classes’ constructor call are specified in the derived
- constructor’s title line. For example:
-
- CPictureButton::CPictureButton( WindowPtr owningWindow, Rect *bounds,
- PicHandle pic, Boolean isDefault )
- : CPushButton( owningWindow, bounds, "\p", isDefault );
-
- I promised an explanation of the mysterious virtual keyword.
- class CPictureButton : public CPushButton
- {
- protected:
- PicHandle pic;
-
- public:
- CPictureButton( WindowPtr owningWindow, Rect *bounds,
- PicHandle pic, Boolean isDefault );
- virtual ~CPushButton();
- virtual void Draw();
- virtual void DoClick();
- };
-
- Now suppose you define a CMyPictureButton object, like this:
-
- CPictureButton *buttonPtr;
-
- buttonPtr = new CMyPictureButton( /* put params here */ );
-
- To call CPictureButton’s version of Draw(), call:
-
- CPictureButton::Draw()
-
-
-